﻿using System;
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;

namespace NetTopologySuite.Noding
{
	public class OrientedCoordinateArray : IComparable
	{
		public OrientedCoordinateArray(Coordinate[] pts)
		{
			this._pts = pts;
			this._orientation = OrientedCoordinateArray.Orientation(pts);
		}

		private static bool Orientation(Coordinate[] pts)
		{
			return CoordinateArrays.IncreasingDirection(pts) == 1;
		}

		public int CompareTo(object o1)
		{
			OrientedCoordinateArray orientedCoordinateArray = (OrientedCoordinateArray)o1;
			return OrientedCoordinateArray.CompareOriented(this._pts, this._orientation, orientedCoordinateArray._pts, orientedCoordinateArray._orientation);
		}

		private static int CompareOriented(Coordinate[] pts1, bool orientation1, Coordinate[] pts2, bool orientation2)
		{
			int num = orientation1 ? 1 : -1;
			int num2 = orientation2 ? 1 : -1;
			int num3 = orientation1 ? pts1.Length : -1;
			int num4 = orientation2 ? pts2.Length : -1;
			int num5 = orientation1 ? 0 : (pts1.Length - 1);
			int num6 = orientation2 ? 0 : (pts2.Length - 1);
			int num7;
			for (;;)
			{
				num7 = pts1[num5].CompareTo(pts2[num6]);
				if (num7 != 0)
				{
					break;
				}
				num5 += num;
				num6 += num2;
				bool flag = num5 == num3;
				bool flag2 = num6 == num4;
				if (flag && !flag2)
				{
					return -1;
				}
				if (!flag && flag2)
				{
					return 1;
				}
				if (flag && flag2)
				{
					return 0;
				}
			}
			return num7;
		}

		private readonly Coordinate[] _pts;

		private readonly bool _orientation;
	}
}
